package day06;

import java.util.Scanner;


public class h1 {
    static Scanner scanner=new Scanner(System.in);
    static boolean b=true;
    static double money=0;
    static int num=0;
    static int[] Num=new int[100];
    public static void main(String[] args){

        while (b){
            Index();
            buy();
        }
        Last();

    }
    static void Index(){
        System.out.print("1.可乐\t10000元\n" +
                "2.番茄\t1元\n" +
                "3.方便面\t2000元\n"+
                "4.牛奶\t1000元\n"+
                "5.结账\n"+
                "当前商品总价："+money+
                "\n你想要什么："
        );
    }
    static void buy(){
        int i=scanner.nextInt();
        switch (i){
            case 1:
                pr();
                money+=num*sp.cola.price;
                sp.cola.n++;
                break;
            case 2:
                pr();
                money+=num*sp.tomato.price;
                sp.tomato.n++;
                break;
            case 3:
                pr();
                money+=num*sp.noodles.price;
                sp.noodles.n++;
                break;
            case 4:
                pr();
                money+=num*sp.milk.price;
                sp.milk.n++;
                break;
            case 5:
                Discount();
                System.out.println("您需要支付"+money+"元\n请支付：");
                b=false;
                break;
            default:
                System.out.println("输入错误,请重新输入!");
                break;
        }
        Num[i]+=num;
    }
    static void Discount( ){
        if(money<=1){
            System.out.println("骂你");
            System.exit(0);
        }
        else if(money>=5000&&money<10000){
            money*=0.95;
        }
        else if(money<20000){
            money*=0.9;
        }
        else {
            money*=0.8;
        }
    }
    static void Last(){
        double price=scanner.nextDouble();
        if(price>money){
            System.out.println("交易完成,找您"+(price-money)+"元,欢迎下次光临！");
        }
        else if(price==money){
            System.out.println("交易完成,欢迎下次光临！");
        }
        else {
            money=money-price;
            System.out.println("支付金额不足，请再支付"+money+"元");
            Last();
        }
    }
    static void pr(){
        System.out.print("你要购买的数量：");
        num=scanner.nextInt();
    }

    static class sp{
        static Price cola= new Price("可乐", 10000);
        static Price tomato= new Price("番茄", 1);
        static Price noodles= new Price("方便面", 2000);
        static Price milk= new Price("牛奶", 1000);

    }
    static class Price{
        int n;
        double price;
        String name;
        Price(){
        }
        Price(String name,int price){
            this.price=price;
            this.name=name;
        }
    }

}

